<layout name="page" />
<block name="content">
	{:widget('page_header/adv_search',array('name'=>'我的客户'))}
	<div id="adv_search" class="hidden">
		<form method="post" name="form_adv_search" id="form_adv_search">
			<div id="adv_search_header" class="row" style="">
				<h1 style="">高级搜索</h1>
				<i class="x1" class=""></i>
				<a class="btn btn-normal" id="submit_adv_search">搜索</a>
				<a class="btn btn-return" id="close_adv_search">关闭</a>
			</div>
			<div class="row" id="adv_search_body" >
				<div class="box col-6">
					<label class=" input-label" for="li_name">姓名：</label>
					<input  class="input" type="text" id="li_name" name="li_name" >
				</div>
				<div class="box col-6">
					<label class=" input-label" for="li_company_name">公司：</label>
					<input  class="input" type="text" id="li_company_name" name="li_company_name" >
				</div>
			</div>
		</form>
	</div>

	<div class="operate-panel">
		<if condition="$auth->admin">
			<a class="btn btn-del" id="btn_del">删除</a>
		</if>
		<i class="x1"></i>
		<a class="btn btn-normal" href="{:url('add')}">新建</a>
		<a class="btn btn-normal" href="{:url('import')}"> 导入 </a>
		<a class="btn btn-normal" href="{:url('transfer')}">转交</a>
		<a class="btn btn-normal" href="{:url('share')}">共享</a>
	</div>
	<div class="sub">
		<form id="form_data" name="form_data" method='post'>
			<div class="table">
				<ul>
					<li class="thead">
						<if condition="$auth->admin">
							<span class="w3"> <label class="checkbox">
									<input type="checkbox" class="toggle-select-all" data='contact_id[]'/>
									<i class="icon"></i></label></span>
						</if>
						<span class="w8">姓名</span>
						<span class="w16 x1">公司</span>
						<span class="w16  ">部门</span>
						<span class="w8  ">职位</span>
						<span class="w13  ">手机号</span>
						<span class="w8  ">创建人</span>
						<span class="w8  ">产品</span>
						<span class="w8">业务员</span>
						<span class="w8">操作</span>
					</li>
					<if condition="empty($list)">
						<li class="no-data">
							没找到数据
						</li>
						<else/>
						<foreach name="list" val="vo">
							<li class="tbody">
								<if condition="$auth->admin">
									<php>
										if($vo['salesman_id']==get_user_id()){
									</php>
									<span class="w3"><label class="checkbox">
											<input  type="checkbox" name="contact_id[]" value="{$vo.id}" />
											<i class="icon"></i></label></span>
									<php>
										}else{
									</php>
									<span class="w3"></span>
									<php>
										}
									</php>
								</if>
								<span class="w8"> <a href="{:url('read','id='.$vo['id'])}">{$vo.name}</a> </span>
								<span class="w16 x1" title="{$vo.company_name}">{$vo.company_name}&nbsp;</span>
								<span class="w16">{$vo.dept}&nbsp;</span>
								<span class="w8">{$vo.position}&nbsp;</span>
								<span class="w13">{$vo.mobile_tel}&nbsp;</span>
								<span class="w8">{$vo.user_name}</span>
								<span class="w8">{$vo.product}&nbsp;</span>
								<span class="w8">{$vo.salesman_name}</span>
								<span class="w8"> <a class="w3" href="{:url('read','id='.$vo['id'])}#add_follow">跟进 </a>
									<if condition="$vo['salesman_id'] = get_user_id()">
										<a class="w3" href="{:url('edit','id='.$vo['id'])}">修改 </a>
									</if></span>
							</li>
						</foreach>
					</if>
				</ul>
			</div>
		</form>
		<if condition="!empty($list)">
			{$page}
		</if>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;

			var layer = layui.layer;

			$('#btn_del').on('click', function() {
				del();
			});

			$(document).keydown(function(e) {
				if (e.keyCode == 46) {
					del();
					return false;
					// 截取返回false就不会保存网页了
				}
			});

			function del() {
				if ($("input[name='contact_id[]']:checked").length == 0) {
					layer.msg('请选择要删除的客户');
					return;
				}
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("{:url('del_contact')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			};
			//保存后关闭
			$('#save').on('click', function() {
				send_form('form_data', '{:url("save")}', '', function(ret) {
					if (ret.status == 1) {
						parent.layer.msg(ret.info);
						parent.layer.close(index);
						parent.location.reload(true);
					}
				});
			});

			//关闭iframe
			$('#close').click(function() {
				parent.layer.close(index);
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:url('winpop')}", 560, 470);
			});

			set_return_url(null);

		});

	</script>
</block>
